import UIKit

// 加法
func plus(a: Int, b: Int) -> Int {
  return a + b
}

// 减
func minus(a: Int, b: Int) -> Int {
  return a - b
}

// 计算器
func calculator(a: Int, b: Int, myOperation: (Int, Int) -> Int) -> Int {
  let res = myOperation(a, b)
  return res
}

// 闭包: 匿名函数
let zhangsan = { (a: Int, b: Int) -> Int in
  a * b
}

let lisi = { (x: Int, y: Int) -> Int in
  x + y + 10
}

calculator(a: 3, b: 5, myOperation: minus(a:b:))
// calculator(a: 2, b: 4, myOperation: <#T##(Int, Int) -> Int#>)
calculator(a: 2, b: 4, myOperation: zhangsan)
calculator(a: 3, b: 4, myOperation: lisi)

// 电饭煲例子

enum Rice {
  case WhiteRice, BlckRice
}

func zhangSanCook(rice: Rice) {
  print("加\(rice)")
  print("加水")
  print("开启煮饭模式")
  print("米饭做好了")
}

zhangSanCook(rice: .BlckRice)

func wangErCook(rice: Rice) {
	print("加\(rice)")
	print("加水")
	print("加红豆")
	print("开启煮饭模式")
	print("米饭做好了")
}
func CookRice(rice: Rice, yourCook: (Rice) -> Void) {
	yourCook(rice)
}
CookRice(rice: .BlckRice, yourCook: wangErCook(rice:))
